Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templater: prep for "branch list -Ttemplate" + minor cleanup #3648

Merged
merged 4 commits into from
May 8, 2024

Conversation

yuja
Copy link
Contributor

@yuja yuja commented May 8, 2024

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

yuja added 4 commits May 8, 2024 17:27
This is a remainder of the previous refactoring series. into_template() could be
implemented as a non-extension method, which allows us to get rid of .clone()
from Literal property extraction. However, there wasn't measurable difference.
Let's not try to overly optimize things. It's probably simpler to switch to
Rc<str> if .clone() really matters.
I'll add a few more optional property types, and I don't want to duplicate the
error message. Type names are capitalized for consistency.
In order to port "branch list" to template, we need to somehow represent
revset.count_estimate() result as a template property. I'm going to add
SizeHint template type for that, and its .upper() and .exact() methods will
have to return optional integers.

Fortunately, the Integer type has no implicit conversion to bool, so
"if(optional_integer, ..)" is not ambiguous.
We'll probably add binary comparison operators at some point, but this patch
also adds size_hint.zero() method. Otherwise, we'll have to write
"if(x.upper() && x.upper() == 0, ..)" to deal with None.

The resulting "branch list" template will look like:
```
separate(", ",
  if(!ref.tracking_ahead_count().zero(),
    if(ref.tracking_ahead_count().exact(),
      "ahead by " ++ ref.tracking_ahead_count().exact() ++ " commits",
      "ahead by at least " ++ ref.tracking_ahead_count().lower() ++ " commits")),
  if(!ref.tracking_behind_count().zero(),
    if(ref.tracking_behind_count().exact(),
      "behind by " ++ ref.tracking_behind_count().exact() ++ " commits",
      "behind by at least " ++ ref.tracking_behind_count().lower() ++ " commits")),
)
```
@yuja yuja merged commit 9a5b001 into jj-vcs:main May 8, 2024
16 checks passed
@yuja yuja deleted the push-myumzvlplrnq branch May 8, 2024 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants